package com.xushi.service.impl;

import com.xushi.dao.TemplateOrderRepository;
import com.xushi.model.Template;
import com.xushi.model.TemplateOrder;
import com.xushi.service.TemplateOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class TemplateOrderServiceImpl implements TemplateOrderService {

    @Qualifier("templateOrderDao")
    @Autowired
    private TemplateOrderRepository templateOrderDao;

    // TODO 如果当前用户有未支付的订单，应当提醒支付
    public TemplateOrder getOrder(String username) {
        return null;
    }

    @Override
    public TemplateOrder createOrder(String username, String subject, String totalAmount, String body, String timeoutExpress, String productCode, int state) {
        TemplateOrder order = new TemplateOrder(username, subject, totalAmount,
                body, timeoutExpress, productCode, state);

        return templateOrderDao.save(order);
    }

    @Override
    public TemplateOrder updateOrder(TemplateOrder order) {
        return templateOrderDao.save(order);
    }

    @Override
    public TemplateOrder findOrderById(int orderNo) {
        return templateOrderDao.findTemplateOrderById(orderNo);
    }
}
